package com.k.kpp.logback.converter;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;

/**
 * 处理 logback 不显示线程 ID
 * 1. 编写 ThreadIdConverter
 * 2. logback.xml 中  <configuration> 下 添加 <conversionRule conversionWord="threadId" converterClass="com.k.kpp.logback.converter.ThreadIdConverter"/>
 * 3. 格式化属性中添加 %threadId <property name="log.pattern" value="%d{HH:mm:ss.SSS} [%threadId] [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
 */
public class ThreadIdConverter extends ClassicConverter {
    @Override
    public String convert(final ILoggingEvent e) {
        return String.valueOf(Thread.currentThread().getId());
    }
}
